package com.shiguiwu.springmybatis.designpattern.decorator;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: 继承的方法实现，不科学的方法
 * @author: stone
 * @date: Created by 2021/8/27 10:05
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.decorator
 */
public class LoginSsoDecorator extends SsoDecorator {

    private static Map<String, String> authMap = new ConcurrentHashMap<>();

    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }


    public LoginSsoDecorator(HandlerInterceptor handlerInterceptor) {
        super(handlerInterceptor);

    }

    @Override
    public boolean preHandle(String request, String response, Object handler) {

        //模拟校验
        boolean success = super.preHandle(request, response, handler);

        if (!success) {
            return false;
        }

        String userId = request.substring(8);
        String method = authMap.get(userId);

        //校验是否有权限访问方法
        return "queryUserInfo".equals(method);
    }

}
